<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
$item=$this->plugin_setting('setting');
if($_RQ['op']=='main'){
	$info=pdo_get('jy_djhome_worker',array('mid'=>$_SESSION['uid']));
	$info['pcd']=json_decode($info['pcd'],true);
	if($info['id'] && $info['status']==0){
		exi('您的申请正在审核，请耐心等待','','/index/');
	}
	$info['sex']=$info['sex']?:2;
	$info['age']=$info['age']?:'';
	$return['item']=$info;
	$is_xieyi=pdo_getcolumn('jy_djhome_worker',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'is_xieyi');
	if(!$is_xieyi && $_SESSION['uid']){
		$return['xieyi']=$this->plugin_setting('siji_xieyi')?:array();
		$return['xieyi']['title']='本平台协议';
		$return['show_xieyi']=$return['xieyi']['content']?true:false;
	}
	$return['sex']=array(1=>'男',2=>'女');
	set_html('title','注册');
	exi($return);
}
if($_RQ['op']=='set'){
	$postdata=get_postdata();
	if(!$postdata['title']){
		exi('请输入昵称','error');
	}
	if(!$postdata['name']){
		exi('请填写姓名','error');
	}
	if(!$postdata['mobile']){
		exi('请填写手机号','error');
	}
	if(!$postdata['age']){
		exi('请输入年龄','error');
	}
	$data=array(
		'title'=>$postdata['title'],
		'name'=>$postdata['name'],
		'desc'=>$postdata['desc'],
		'sex'=>$postdata['sex'],
		'age'=>$postdata['age'],
		'mobile'=>$postdata['mobile'],
		'avatar'=>$postdata['avatar'],
		'cardimg1'=>$postdata['cardimg1'],
		'cardimg2'=>$postdata['cardimg2'],
		'pcd'=>ijson_encode($postdata['pcd']),
		'address'=>$postdata['address'],
	);
	$info=pdo_get('jy_djhome_worker',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	if($info){
		pdo_update('jy_djhome_worker',$data,array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
		exi('更新成功！','','/whome/');
	}else{
		$data['mid']=$_SESSION['uid'];
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=TIMESTAMP;
		pdo_insert('jy_djhome_worker',$data);
		exi('申请成功！','','/whome/');
	}
}
if($_RQ['op']=='set_xieyi'){
	pdo_update('jy_djhome_worker',array('is_xieyi'=>1),array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	exi('你已同意本协议！');	
}
?>